package com.shopping.service;

import java.util.Date;
import java.util.List;

import com.shopping.dao.SaleItemDAO;
import com.shopping.dao.SaleOrderDAO;
import com.shopping.modean.Product;
import com.shopping.modean.SaleOrder;

public class OrderService {

	private static OrderService orderService = null;
	
	private SaleOrderDAO saleOrderDAO;
	private SaleItemDAO saleItemDAO;
	
	private OrderService() { }
	
	public static OrderService getInstance() {
		if(orderService == null) {
			orderService = new OrderService();
			orderService.setSaleOrderDAO(new SaleOrderDAO() );
			orderService.setSaleItemDAO(new SaleItemDAO());
		}
		return orderService;
	}
	
	/**
	 * 创建订单
	 * 
	 * @date 2018-06-25
	 */
	public void add(SaleOrder o) {
		saleOrderDAO.insert(o);
		saleItemDAO.insertBath(o.getId(),o.getSaleItem());
	}
	
	/**
	 * 修改商品
	 * 
	 * @date 2018-06-23
	 */
	/*public void update(Product p) {
		productDAO.updateById(p);
	}*/
	
	/**
	 * 商品详情
	 * 
	 * @date 2018-06-23
	 */
	/*public Product detail(int id) {
		return productDAO.getProductById(id);
	}*/
	
	
	/**
	 * 分页获取商品
	 * 
	 * @date 2018-06-26
	 */
	public List<SaleOrder> getOrders(int pageNo,int pageSize) {
		return saleOrderDAO.getOrders(pageNo,pageSize);
	}
	
	/**
	 * 分页获取最新商品
	 * 
	 * @date 2018-06-24
	 */
	/*public List<Product> getLasterProducts(int count) {
		return productDAO.getLasterProducts(count);
	}*/
	
	/**
	 * 获取总页数
	 * 
	 * @date 2018-06-20
	 */
	/*public int getTotalCount(int pageSize) {
		return  productDAO.getTotalCount();
	}*/
	
	
	/**
	 * 获取商品
	 * 
	 * @date 2018-06-20
	 */
	public List<Product> getProducts() {
		
		return null;
	}
	
	/**
	 * 指定条件搜索商品
	 * 
	 * @date 2018-06-20
	 */
	public List<Product> searchProducts(int categoryId,
									    String name,
			                            String descr,
			                            double lowNormalPrice,
			                            double highNormalPrice,
			                            double lowMemberPrice,
			                            double highMemberPrice,
			                            Date startDate,
			                            Date endDate,
			                            int pageNo,
			                            int pageSize) {
		
		return null;
	}
	
	/**
	 * 删除
	 * 
	 * @date 2018-06-20
	 */
	public boolean deleteById(int id) {
		
		return false;
	}

	public SaleOrderDAO getSaleOrderDAO() {
		return saleOrderDAO;
	}
	public void setSaleOrderDAO(SaleOrderDAO saleOrderDAO) {
		this.saleOrderDAO = saleOrderDAO;
	}
	public SaleItemDAO getSaleItemDAO() {
		return saleItemDAO;
	}
	public void setSaleItemDAO(SaleItemDAO saleItemDAO) {
		this.saleItemDAO = saleItemDAO;
	}



	

	
}
